//
//  PosterCell.m
//  Mtime
//
//  Created by Mac on 15/8/1.
//  Copyright (c) 2015年 wxk. All rights reserved.
//

#import "PosterCell.h"
#import "PosterDetailView.h"

@implementation PosterCell
{
    UIImageView *imageView;
    
    BOOL _isLeft;
    
    PosterDetailView *_detailView;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setModel:(HomeModel *)model {

    _model = model;

    [imageView setImageWithURL:[NSURL URLWithString:_model.img]];
    
    _detailView.model = model;
}

- (id)initWithFrame:(CGRect)frame {

    if (self = [super initWithFrame:frame]) {
    
        imageView = [[UIImageView alloc] initWithFrame:self.contentView.bounds];
        
        [self.contentView addSubview:imageView];
    
    
//        _detailView = [[UIView alloc] initWithFrame:self.contentView.bounds];
        _detailView = [[[NSBundle mainBundle] loadNibNamed:@"PosterDetailView" owner:nil options:nil] lastObject];
        _detailView.frame = self.contentView.bounds;
        
        [self.contentView addSubview:_detailView];
        
        [self.contentView bringSubviewToFront:imageView];
        
    }

    return self;
}

- (void)flipAction {

    UIViewAnimationOptions options = _isLeft? UIViewAnimationOptionTransitionFlipFromLeft:UIViewAnimationOptionTransitionFlipFromRight;

    [UIView transitionWithView:self.contentView duration:.35 options:options animations:^{
        
        [self.contentView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
        
    } completion:^(BOOL finished) {
       
        _isLeft = !_isLeft;
    }];
}


- (void)bringAction {

    [self.contentView bringSubviewToFront:imageView];

}

@end
